package com.bsj.power.system.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.def.dto.personGroup.PersonGroupDTO;
import com.bsj.power.common.def.dto.personGroup.PersonGroupSearchDTO;
import com.bsj.power.common.def.entity.personGroup.PersonGroup;
import com.bsj.power.common.def.vo.PersonGroupVO;
import com.bsj.power.system.service.PersonGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LiJiaXin
 * @version 1.0.0
 * @description PersonGroupController
 * @time 2024/9/7 9:54
 */
@RestController
@RequestMapping("/system/personGroup")
//@SaCheckPermission("/master/system/personGroup")
public class PersonGroupController {

    @Autowired
    private PersonGroupService personGroupService;

    /**
     * 添加人员组
     *
     * @param personGroupDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/9/7 10:54
     */
    @PostMapping("/add")
    public JsonResult add(@Validated @RequestBody PersonGroupDTO personGroupDTO) {
        return personGroupService.addPersonGroup(personGroupDTO);
    }

    /**
     * 删除人员组
     *
     * @param groupId
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/9/7 10:54
     */
    @PostMapping("/delete/{groupId}")
    public JsonResult delete(@PathVariable("groupId") Integer groupId) {
        return personGroupService.deletePersonGroup(groupId);
    }

    /**
     * 修改人员组
     *
     * @param personGroupDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/9/7 10:55
     */
    @SaIgnore
    @PostMapping("/update")
    public JsonResult update(@Validated @RequestBody PersonGroupDTO personGroupDTO) {
        return personGroupService.updatePersonGroup(personGroupDTO);
    }

    /**
     * 获取单个人员组
     *
     * @param groupId
     * @return com.bsj.power.common.config.global.JsonResult<com.bsj.power.common.def.entity.personGroup.PersonGroup>
     * @author ljx
     * @time 2024/9/7 10:55
     */
    @GetMapping("/getById/{groupId}")
    public JsonResult<PersonGroup> getById(@PathVariable("groupId") Integer groupId) {
        return JsonResult.success(personGroupService.getPersonGroupById(groupId));
    }

    /**
     * 人员组分页
     *
     * @param personGroupSearchDTO
     * @return com.bsj.power.common.config.global.JsonResult<java.util.List < com.bsj.power.common.def.vo.PersonGroupVO>>
     * @author ljx
     * @time 2024/9/7 10:55
     */
    @GetMapping("/page")
    public JsonResult<List<PersonGroupVO>> page(PersonGroupSearchDTO personGroupSearchDTO) {
        return personGroupService.pagePersonGroup(personGroupSearchDTO);
    }

}
